$import( "SmitearWebGL.Objects.Parser.Collada.DaeEntity" );
$import( "SmitearWebGL.Objects.Parser.Collada.DaeInstanceMaterial" );

SmitearWebGL.Objects.Parser.Collada.DaeBindMaterial = SmitearWebGL.Objects.Parser.Collada.DaeEntity.extend(
{
	/******** constructor ********/

	init : function( document, node )
	{
		this.instanceMaterials = null;

		this._super( document, node );
		this._registClass( "SmitearWebGL.Objects.Parser.Collada.DaeBindMaterial" );
	}
	,
	destroy : function()
	{
		this._super();

		if( this.instanceMaterials )
		{
			for ( var i = 0; i < this.instanceMaterials.length; ++ i )
			{
				this.instanceMaterials[i].destroy();
			}
			this.instanceMaterials = null;
		}
	}
	,
	getInstanceMaterialBySymbol : function( symbol )
	{
		if(this.instanceMaterials)
		{
			for ( var i = 0; i < this.instanceMaterials.length; ++ i )
			{
				var instanceMaterial = this.instanceMaterials[i];
				if(instanceMaterial.symbol == symbol)
				{
					return instanceMaterial;
				}
			}
		}
		return null;
	}
	,
	read : function( node )
	{
		this._super( node );

		var list = node.getElementsByTagName( SmitearWebGL.Objects.Parser.Collada.Const.DAE_INSTANCE_MATERIAL_ELEMENT );

		this.instanceMaterials = [];

		for( var i = 0; i < list.length; i ++ )
		{
			this.instanceMaterials.push( new SmitearWebGL.Objects.Parser.Collada.DaeInstanceMaterial( this.document, list[i] ) );
		}
	}
}
);